package com.kabigon.tiny.test.bean;

import cn.hutool.core.lang.Console;
import cn.hutool.json.JSONUtil;
import com.kabigon.tiny.test.bean.dto.UserDTO;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StreamCollection {
    public static void main(String[] args) {
        List<UserDTO> users = new ArrayList<>();
        users.add(new UserDTO("Alice", 25, "Female", true));
        users.add(new UserDTO("Bob", 30, "Male", false));
        users.add(new UserDTO("Charlie", 25, "Male", true));
        users.add(new UserDTO("Diana", 30, "Female", false));

        Map<Integer, Map<String, List<UserDTO>>> collect = users.stream().collect(Collectors.groupingBy(UserDTO::getAge, Collectors.groupingBy(UserDTO::getSex)));
        Console.log(JSONUtil.toJsonStr(collect));

    }
}
